<template>
  <vxe-column
    :field="prop"
    :title="label"
    :width="width"
    :min-width="minWidth"
    :fixed="innerFixed"
    :align="align"
    :sortable="sortable"
    :tree-node="treeNode"
  >
    <template slot="header" slot-scope="scope">
      <slot name="header">
        <div class="ui-grid-column__main">
          <div class="ui-grid-column__main-left">
            <span class="ui-grid-column__title" :title="scope.column.title">
              {{ scope.column.title }}
            </span>
            <span class="ui-grid-column__tips" v-if="$slots.tips">
              <slot name="tips"></slot>
            </span>
          </div>
          <slot name="header-append"></slot>
        </div>
      </slot>
    </template>
    <template slot-scope="scope">
      <slot v-bind="scope">
        {{ scope.row[scope.column.field] }}
      </slot>
    </template>
  </vxe-column>
</template>
<script>
import { Column } from 'vxe-table'

export default {
  name: 'UiGridColumn',
  components: {
    VxeColumn: Column
  },
  props: {
    label: {
      type: String
    },
    prop: {
      type: String
    },
    width: {
      type: String
    },
    minWidth: {
      type: String
    },
    align: {
      type: String
    },
    fixed: {
      type: Boolean
    },
    sortable: {
      type: Boolean
    },
    treeNode: {
      type: Boolean
    }
  },
  computed: {
    innerFixed () {
      return this.fixed ? 'left' : null
    }
  }
}
</script>
<style lang="less">
.ui-grid-column__tips{
  display: inline-block;
  margin-top: 1px;
  vertical-align: top;
  height: 20px;
  line-height: 20px;
  margin-left: 3px;
}
.ui-grid-column__main{
  width: 100%;
  display: flex;
  flex-direction: row;
  justify-content: space-between;
}
.ui-grid-column__main-left{
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: row;
}
.ui-grid-column__title{
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
</style>
